<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <link rel="stylesheet" href="/css/layui.css">
</head>
<body>
<div class="teacherLogin" style="width: 400px;margin: 150px auto;position: absolute;left: 35%;">
    <form class="layui-form layui-form-pane" id="formLogin" >
        <div class="layui-form-item">
            <label class="layui-form-label">账号</label>
            <div class="layui-input-inline">
                <input type="text" name="userName" lay-verify="required" lay-reqText="请输入正确的账号" placeholder="请输入账号" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">密码框</label>
            <div class="layui-input-inline">
                <input type="password" name="password" lay-verify="required" lay-reqText="请输入正确的密码" placeholder="请输入密码" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <button  class="layui-btn" lay-submit lay-filter="doSubmit">登录</button>
            <button  class="layui-btn">重置</button>
        </div>
    </form>
</div>
</body>
<script src="/js/jquery-1.8.3.js"></script>
<script src="/layui.js"></script>

<script>
    layui.use(['form'],function () {
        let form=layui.form;

        //监听表单提交事件
        form.on("submit(doSubmit)",function (data) {
            $.post("/login",data.field,function (result) {
                if (result.success == "true"){
                    layui.layer.alert("登录成功！",{icon:6,time:2000});
                    setTimeout(function () {
                        // alert(result.msg);
                        switch (result.msg) {
                            case "student":
                                location="student/studentMain.html";
                                break;
                            case "teacher":
                                location="/teachers/teacherMain.html";
                                break;
                            case "parents":
                                location="/parents/main.html";
                                break;
                            case "admin":
                                location="AdminMain.html";
                                break;
                        }
                    }, 1000*1.5)
                } else {
                    layui.layer.alert(result.msg,{icon:5});
                }
            });
            return false;
        })

    });
</script>
</html>